package com.gc.gc.code.filter;

import com.google.code.kaptcha.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationServiceException;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler;
import org.springframework.util.StringUtils;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class CodeFilter extends HttpFilter {
//    @Autowired
//    private SimpleUrlAuthenticationFailureHandler authenticationFailureHandler;
//
//    @Override
//    protected void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain chain) throws IOException, ServletException {
//
//        String uri = req.getServletPath();
//        if (uri.equals("/login/verification") && req.getMethod().equalsIgnoreCase("post")) {
//            // 服务端生成的验证码数据
//            String sessionCode = req.getSession().getAttribute(Constants.KAPTCHA_SESSION_KEY).toString();
//            System.out.println("正确的验证码: " + sessionCode);
//            // 用户输入的验证码数据
//            String formCode = req.getParameter("verifyCodeActual").trim();
//            System.out.println("用户输入的验证码: " + formCode);
//            if (StringUtils.isEmpty(formCode)) {
//                throw new BadCredentialsException("验证码不能为空");
//            }
//            if (sessionCode.equals(formCode)) {
//                System.out.println("验证通过");
//            } else {
//                throw new BadCredentialsException("验证码输入不正确");
//            }
//        }
//        chain.doFilter(req, res);
//    }
}
